<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>Document</title>
</head>

<body>
	<?php
$file = $_FILES["file"];
if(isset($file)) {
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $file["name"]);
$extension = end($temp);
   if((($file["type"] == "image/git") || ($file["type"] == "image/jpeg") 
       || ($file["type"] == "image/jpg") || ($file["type"] == "image/png"))
       && ($file["size"] < 204800)  && in_array($extension, $allowedExts)) {
            if($file["error"] > 0) {
               echo "错误信息: " . $_FILES['file']['orror'];
            }else {
               echo "文件的名字: ". $file["name"]. "<br>";
               echo "文件的类型: ". $file["type"]. "<br>";
               echo "文件的大小: ". ($file["size"] /1024). " kB<br>";
               echo "文件临时存储位置: ". $file["tmp_name"] ."<br>";
               //为了不同用户的上传需求可以 图片名字+时间戳+扩展名;
               date_default_timezone_set('PRC'); 
               $currentDate = date('Ymdhis', time());   // 20161231050705
               $newFileName = $currentDate . $file["name"];
               if(file_exists("upload/" . $newFileName)) {
                   echo $file["name"]. "文件已经存在.";
               }else {
                   // 如果 upload 目录不存在该文件则将文件上传到 upload 目录下
                   move_uploaded_file($file["tmp_name"], "upload/". $newFileName);
                   echo "文件存储在" . "upload/".$newFileName;
               }
            }
        }else {
            echo "非法的文件格式!";
        }
}else {
        echo "文件上传失败!";
    }
?>
</body>

</html>